#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "export.h"
#include "mask.h"


int
main(int argc, void *argv[]) {

  int *tNpoints, Npoints; /* The number of input RA/DEC positions */
  double *RA, *DEC;       /* Input RA/DEC positions */
  double *comp;            /* The completeness array, to be filled in */
  IDL_LONG *poly_id;      /* The polygon id of each point */
  int id;
  double *poly_area;       /* Area of this polygon */

  double x[3];            /* x,y,z version of RA/DEC on unit sphere */
  double tra, tdec;       /* temporary variables to hold RA[i],DEC[i] */
  double theta, phi;      /* convert RA/DEC to theta phi */
  double tcomp;           /* temporary variable to hold comp */
  int i;                 /* loop variable */
  int retval;            /* value to return */
  char *mask_file_string;  /* The mask file in IDL_STRING format */
  int test;
  extern int nr,nc[nrmax];
  extern double caparea[nrmax],capweight[nrmax];
  extern double r[3][50][nrmax],c[50][nrmax];

  FILE *fp;
  
  mask_file_string = (char *) argv[0];
  tNpoints = (int *) argv[1];
  RA       = (double *) argv[2];
  DEC      = (double *) argv[3];
  comp     = (double *) argv[4];
  poly_id  = (IDL_LONG *) argv[5];
  poly_area = (double *) argv[6];

  Npoints = *tNpoints;

  /*printf("MaskFile: %s\n\n", mask_file_string);*/

  /*---Load-Mask-Info---------------------------------------------------*/
  loadmask(mask_file_string);

  for(i=0;i<Npoints;i++) {

    tra  = *(RA + i);
    tdec = *(DEC + i);
    
    theta = (90-tdec)*pi/180.0 ;
    phi = tra*pi/180.0 ;
    
    x[0] = sin(theta)*cos(phi) ;
    x[1] = sin(theta)*sin(phi) ;
    x[2] = cos(theta) ;
    
    test = completeness_id(x, &comp[i], &id, &poly_area[i]);

    poly_id[i] = (IDL_LONG) id;
    
  }


}
